package com.btex.app.treaty.list;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.btex.app.R;
import com.btex.app.entity.TreatyDishListInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/16
 * @time 下午12:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class EntrustListsellAdapter extends BaseQuickAdapter<TreatyDishListInfo.DataBean.ShortBean, BaseViewHolder> {

    private double max;
    private String mChangeType;
    private String mNumbers;
    private String mReverse;
    private String mIsreverseNumber;
    private String mContractvalue = "1";

    public EntrustListsellAdapter(@Nullable List<TreatyDishListInfo.DataBean.ShortBean> data) {
        super(R.layout.fragment_entrust_list_sell, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TreatyDishListInfo.DataBean.ShortBean item) {


        TextView item_treaty_tv_sell_number = (TextView) helper.getView(R.id.item_treaty_tv_sell_number);
        TextView item_treaty_tv_sell_price = (TextView) helper.getView(R.id.item_treaty_tv_sell_price);
        ProgressBar fragment_entrust_pro = (ProgressBar) helper.getView(R.id.fragment_entrust_pro);
        fragment_entrust_pro.setMax((int) max);
        fragment_entrust_pro.setProgress(Integer.valueOf(item.getAmount()));


        if (!TextUtils.isEmpty(mNumbers)) {

            Log.i("wiehfiwuehfiwuefhweh", mNumbers);
            String trim = Tools.round(Double.valueOf(item.getPrice()), Integer.valueOf(mNumbers)).toString().trim();
            item_treaty_tv_sell_price.setText(trim);

        } else {

            if (!TextUtils.isEmpty(item.getPrice())) {
                String price = item.getPrice();
                String[] split = price.split("\\.");
                String s = split[1];
                if (s.length() > 4) {
                    String substring = s.substring(0, 4);
                    String s1 = split[0] + "." + substring;
                    item_treaty_tv_sell_price.setText(s1);
                } else {
                    item_treaty_tv_sell_price.setText(item.getPrice());
                }


            }

        }


        Log.i("weljiwoeifjowief", mChangeType);

        if (mChangeType.equals("1")) {

            Log.i("weufiwuefiwuefgiwe", "1");
            item_treaty_tv_sell_number.setText(item.getAmount());


        } else {
            Log.i("weufiwuefiwuefgiwe", "2");
            String amount = item.getAmount();
            String price = item.getPrice();

            if (!TextUtils.isEmpty(mReverse)) {

                Log.i("weufiwuefiwuefgiwe", "3");

                if ("1".equals(mReverse)) {
                    Log.i("weufiwuefiwuefgiwe", "4");
                    Double aDoubleamount = Double.valueOf(amount);
                    Double aDoubleprice = Double.valueOf(price);
                    double v = aDoubleamount / aDoubleprice * Double.valueOf(mContractvalue);
                    if (!TextUtils.isEmpty(mIsreverseNumber)) {
                        String trim = Tools.round(v, Integer.valueOf(mIsreverseNumber)).toString().trim();
                        item_treaty_tv_sell_number.setText(trim);
                    }

                } else {
                    Log.i("weufiwuefiwuefgiwe", "5");
                    Double aDoubleamount = Double.valueOf(amount);
                    Double aDoubleprice = Double.valueOf(price);
                    double v = aDoubleamount * aDoubleprice * Double.valueOf(mContractvalue);

                    if (!TextUtils.isEmpty(mIsreverseNumber)) {
                        Log.i("weufiwuefiwuefgiwe", "6");
                        String trim = Tools.round(v, Integer.valueOf(mIsreverseNumber)).toString().trim();
                        item_treaty_tv_sell_number.setText(trim);
                    }


                }


            }

        }


    }

    public void setValue(double max) {


        this.max = max;
    }

    public void settype(String Type) {


        this.mChangeType = Type;
    }

    public void setNumber(String numbers) {

        mNumbers = numbers;
    }

    public void setIsreverse(String reverse) {

        mReverse = reverse;
    }

    public void setIsreverseNumber(String IsreverseNumber) {

        mIsreverseNumber = IsreverseNumber;
    }

    public void setContractValue(String contractvalue) {

        mContractvalue = contractvalue;
    }

}
